/*
 * deletePCB.c
 *
 *  Created on: Oct 2, 2013
 *      Author: Joseph DeLong
 */

#include <stdlib.h>

/*
 * DELETE PCB
 * Written by Joseph DeLong
 * Debugged by Alex Newcomer
 * Removes the PCB from its queue and frees its memory by calling the remove_PCB() and then free_PCB()
 * Parameters: Process Name
 * Error Checking:
 * 	Name must be valid
 * Should display a success or error message
 */
void deletePCB(char processName[9], struct MPX_Q *r, struct MPX_Q *b) {
	struct MPX_PCB *temp = findPCB(processName);
	int i;
	if(temp == NULL) { //didn't find named PCB
		printf("Couldn't find PCB named %s.\n", processName);
	}
	else { //found the PCB!
		i += removePCB(temp,r,b);
		i += freePCB(temp);
		if(i != 0) { //if error codes were returned on either of the previous 2 function calls
			printf("ERROR: Unable to completely delete PCB %s from the system!\n", processName);
		}
		else { //else all is OK!
			printf("PCB %s has been successfully deleted from the system!\n", processName);
		}
	}
}
